using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;

namespace ClientTools.Client
{
    public sealed class Globals
    {
        private static string _appPath;
        public static string AppPath 
        {
            get { return _appPath; }
            set { _appPath = value; }
        }

        private static global::ClientTools.Client.Library.Settings.ClientTools _appSettings;

        public static global::ClientTools.Client.Library.Settings.ClientTools AppSettings
        {
            get 
            {
                if (Globals._appSettings == null) { 
                    string path = System.IO.Path.Combine(_appPath, "ClientTools.config");
                    if (System.IO.File.Exists(path))
                    {
                        System.Xml.Serialization.XmlSerializer ser 
                            = new System.Xml.Serialization.XmlSerializer(typeof(Library.Settings.ClientTools));
                        using (System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open))
                        {
                            Globals._appSettings = (Library.Settings.ClientTools)ser.Deserialize(fs);
                            fs.Close();
                        }
                    } 
                    else
                    {
                        _appSettings = new global::ClientTools.Client.Library.Settings.ClientTools();
                        _appSettings.AddNewProfile();
                    }
                }
                return Globals._appSettings; 
            }
        }

        public static void SaveSettings()
        {
            string path = System.IO.Path.Combine(_appPath, "ClientTools.config");
            using (System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Create))
            {
                System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(typeof(Library.Settings.ClientTools));
                ser.Serialize(fs, Globals.AppSettings);
                fs.Close();
            }
        }

    }
}
